package order;

import chart.Figure;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: fzykd
 * Date: 2023-03-21
 * Time: 21:59
 */

public class OrderChart {
    //构造器 创建工厂
    public OrderChart(SimpleFactory simpleFactory){
        setFactory(simpleFactory);
    }
    //定义简单工厂对象
    SimpleFactory simpleFactory;
    Figure figure = null;
    private void setFactory(SimpleFactory simpleFactory) {
        String oderType = "";
        this.simpleFactory = simpleFactory;

        do {
            oderType = getType();
            figure = this.simpleFactory.createFigure(oderType);

            if (figure != null){
                figure.draw();
            }else {
                System.out.println("没有这个图形");
                break;
            }

        }while (true);

    }
    private String getType() {
        try {
            BufferedReader strin = new BufferedReader(new InputStreamReader(System.in));
            System.out.println("input pizza type:");
            String str = strin.readLine();
            return str;
        } catch (IOException e) {
            e.printStackTrace();
            return "";
        }
    }

}
